package com.example.xyxwebbackend001.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.xyxwebbackend001.model.entity.Food;
import com.example.xyxwebbackend001.model.entity.TradCraft;
import com.example.xyxwebbackend001.model.vo.ComArtDetailsVO;
import com.example.xyxwebbackend001.model.vo.CommendListVO;
import com.example.xyxwebbackend001.model.vo.FoodListVO;
import com.example.xyxwebbackend001.model.vo.TradCraftListVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TradCraftMapper extends BaseMapper<TradCraft> {

    @Select("<script>" +
            "SELECT tr_id as commend_id, title, city_id, cover_path FROM trad_craft " +
            "WHERE status = 1 " +
            "<if test='cityId != null'>" +
            "    AND city_id = #{cityId} " +
            "</if>" +
            "</script>")
    List<CommendListVO> getTradCraftList(@Param("cityId")String cityId);


    ComArtDetailsVO selectTradCraftDetailsById(@Param("tradCraftId")String tradCraftId);

    @Select("<script>" +
            "SELECT " +
            "   tr_id AS id," +
            "   title," +
            "   (SELECT city_name FROM city WHERE city_id = t.city_id) AS cityName," +
            "   status," +
            "   DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s') AS createTime " +
            "FROM trad_craft t " +
            "WHERE status != 2 " +
            "<if test='keyword != null and keyword != \"\"'>" +
            "   AND title LIKE CONCAT('%', #{keyword}, '%')" +
            "</if> " +
            "ORDER BY create_time DESC" +
            "</script>")
    List<TradCraftListVO> getCraftList(@Param("keyword") String keyword);
}
